package com.zf.shuashua.api;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.text.TextUtils;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.luck.picture.lib.tools.SPUtils;
import com.umeng.analytics.MobclickAgent;
import com.umeng.message.PushAgent;
import com.vise.xsnow.http.callback.ACallback;
import com.zf.shuashua.MainActivity;
import com.zf.shuashua.ShuaApplication;
import com.zf.shuashua.bean.ConfigInfo;
import com.zf.shuashua.bean.LoginBean;
import com.zf.shuashua.bean.Me;
import com.zf.shuashua.bean.advert.AdvertConfigBean;
import com.zf.shuashua.manager.ReportChannelManager;
import com.zf.shuashua.ui.mine.LogUtil;
import com.zf.shuashua.ui.mine.LoginActivity;
import com.zf.shuashua.utils.ToastUtil;
import com.zf.shuashua.utils.Util;

import java.util.List;

public class Store {
    private static Store instance;
    private SharedPreferences mStore;
    private static final String SP_RX = "sp_rx";
    private static final String TOKEN = "token";
    private static final String ACCESS_TOKEN = "access_token";
    private static final String OPEN_ID = "open_id";
    private static final String WECHAT = "wechat";
    private static final String VIDEO_ID = "video_id";


    private static final String isPRIVACY = "isPRIVACY";//第一次隐私政策

    private static final String BACK_TASKS_TIME = "back_tasks_time";//后台任务时间
    private static final String BACK_TASKS_PUPOP_DAY = "back_tasks_pupop_day";//后台任务弹几天
    private static final String BACK_TASKS_PUPOP_SUM = "back_tasks_pupop_sum";//后台任务弹几次

    private static final String BACK_TASKS_PUPOP_WHICHDAY = "BACK_TASKS_PUPOP_WHICHDAY";//哪一天弹


    private static final String agent_code = "agent_code";//邀请码
    private static final String USER_ID = "user_id";//用户id
    private static final String USER_NAME = "user_name";//邀请码
    private static final String USER_PHONE = "user_phone";//用户手机号
    private static final String IS_NEW_USER = "is_new_user";//是不是新人

    private static final String LAST_LOCATION = "last_location";//定位城市
    private static final String MISTAKE_CONFIG = "mistake_config";//误触配置

    private static final String IS_AD_OPEN = "is_ad_open";//开屏广告误触
    private static final String IS_AD_NEW_OPEN = "is_ad_new_open";//新用户误触
    private static final String IS_AD_OLD_OPEN = "is_ad_old_open";//老用户误触
    private static final String AD_SKIP_TIME = "ad_skip_time";//开屏剩余几秒可跳过, 单位(秒)
    private static final String FIRST_AD = "first_ad";//新用户广告控制

    private static final String IS_HUAWEI_OPEN = "is_huawei_open";//华为审核开关
    private static final String IS_VIVO_OPEN = "is_vivo_open";//华为审核开关
    private static final String IS_XIAOMI_OPEN = "is_xiaomi_open";//小米审核开关

    private static final String IS_FIRST_START = "is_first_start";//第一次启动
    private static final String IS_NEWUSER_POPUOP = "IS_NEWUSER_POPUOP";//新人红包是否弹过窗

    private static final String IS_REMIND_LOCATION = "is_remind_location";//是否提醒过定位权限


    // 是否限制自动播放引导
    private static final String AUTO_PLAY_GUIDE = "auto_play_guide";

    private static final String ADVERT_RATE = "advert_rate";//频率
    private static final String HORIZONTAL_RATE = "horizontal_rate";//横屏信息流频率
    private static final String ADVERT_DRAW = "advert_draw";//draw信息流广告配置
    private static final String ADVERT_OPEN = "advert_open";//open信息流广告配置
    private static final String INDEX_OPEN = "index_open";//open 开屏的索引位置
    private static final String INDEX_DRAW = "index_draw";//draw 开屏的索引位置
    private static final String INDEX_BUTTLE = "index_buttle";//首页泡泡的索引位置
    private static final String INDEX_NATIVE_CASH = "index_native_cash";//提现贴片的索引位置
    private static final String INDEX_NATIVE_COMMON = "index_native_common";//公用贴片的索引位置
    private static final String INDEX_NATIVE_REWARD = "index_native_reward";//奖励贴片的索引位置
    private static final String ADVERT_HORIZONTAL = "advert_horizontal";//draw信息流广告配置
    private static final String IS_ADMOBILE_OPEN = "is_admobile_open";//admobile是否开启
    private static final String IS_TUIA_HOME_OPEN = "is_tuia_home_open";//推啊悬浮框
    private static final String IS_TUIA_TASK_OPEN = "is_tuia_tak_open";//推啊插屏
    private static final String IS_BXM_OPEN = "is_bxm_open";//变现猫广告开关
    private static final String IS_HW_AD_OPEN = "is_hw_ad_open";//华为广告开关

    //手势指
    private static final String BUTTLE_FIRST_GUIDE = "buttle_fist_guide";//第一个泡泡手势指引
    private static final String BUTTLE_LAST_GUIDE = "buttle_last_guide";//第六个泡泡手势指引

    private static final String IS_GOLD_GUIDE = "is_gold_guide";

    private static final String IS_PROXY = "is_proxy";

    private static final String CALENDAR_IS_REMIND = "calendar_is_remind";
    private static final String TP_AD = "TP_AD";//贴片误触开关
    public static int min;//贴片最小值
    public static int max;//贴片最大值
    private static final String NEW_USER_TP_AD = "new_user_tp_ad";//新用户贴片开关

    private static final String IS_GUIDE_DOUBLE = "is_guide_double";//泡泡翻倍引导是否显示过
    private static final String IS_PAOPAO_TIME = "is_paopao_time";//泡泡每天弹窗
    //新手提示
    private static final String IS_NEW_LOCK_VIDEO = "new_lock_video";//上滑查看视频手势
    private static final String NEW_DOUCLICK = "new_douclick";//双击屏幕手势
    private static final String NEW_REWARD = "new_Reward";//金豆进度条指引
    private static final String NEW_CLICKBUBBLE = "clickbubble";//引导点击泡泡手势

    private static final String NEW_OR_OLD = "new_or_old"; //新老用户（当天新用户），，，false老用户

    public void setNEW_OR_OLD(boolean o) {
        mStore.edit().putBoolean(NEW_OR_OLD, o).apply();
    }

    public boolean getNEW_OR_OLDE() {
        return mStore.getBoolean(NEW_OR_OLD, false);
    }


    public void setNEW_CLICKBUBBLE(boolean o) {
        mStore.edit().putBoolean(NEW_CLICKBUBBLE, o).apply();
    }

    public boolean getNEW_CLICKBUBBLE() {
        return mStore.getBoolean(NEW_CLICKBUBBLE, true);
    }

    public void setNEW_REWARD(boolean o) {
        mStore.edit().putBoolean(NEW_REWARD, o).apply();
    }

    public boolean getNEW_REWARD() {
        return mStore.getBoolean(NEW_REWARD, true);
    }

    public void setNEW_DOUCLICK(boolean o) {
        mStore.edit().putBoolean(NEW_DOUCLICK, o).apply();
    }

    public boolean getNEW_DOUCLICK() {
        return mStore.getBoolean(NEW_DOUCLICK, true);
    }

    public void setNEW_LOCK_VIDEO(boolean o) {
        mStore.edit().putBoolean(IS_NEW_LOCK_VIDEO, o).apply();
    }

    public boolean getNEW_LOCK_VIDEO() {
        return mStore.getBoolean(IS_NEW_LOCK_VIDEO, true);
    }


    public void setisPaopaoTime(String userId) {
        mStore.edit().putString(IS_PAOPAO_TIME, userId).apply();
    }

    public String getPaopaoTime() {
        return mStore.getString(IS_PAOPAO_TIME, "");
    }

    public void setGuideDouble(boolean o) {
        mStore.edit().putBoolean(IS_GUIDE_DOUBLE, o).apply();
    }

    public boolean getGuideDouble() {
        return mStore.getBoolean(IS_GUIDE_DOUBLE, false);
    }


    public void setBackTasksPupopSum(int o) {
        mStore.edit().putInt(BACK_TASKS_PUPOP_SUM, o).apply();
    }

    public int getBackTasksPupopSum() {
        return mStore.getInt(BACK_TASKS_PUPOP_SUM, -1);
    }

    public void setBackTasksPupopWhichday(String userId) {
        mStore.edit().putString(BACK_TASKS_PUPOP_WHICHDAY, userId).apply();
    }

    public String getBackTasksPupopWhichday() {
        return mStore.getString(BACK_TASKS_PUPOP_WHICHDAY, "");
    }


    public void setBackTasksPupopDay(int o) {
        mStore.edit().putInt(BACK_TASKS_PUPOP_DAY, o).apply();
    }

    public int getBackTasksPupopDay() {
        return mStore.getInt(BACK_TASKS_PUPOP_DAY, -1);
    }

    public void setNewUserTpAd(int o) {
        mStore.edit().putInt(NEW_USER_TP_AD, o).apply();
    }

    public int getNewUserTpAd() {
        return mStore.getInt(NEW_USER_TP_AD, 0);
    }


    public void setTP_AD(boolean o) {
        mStore.edit().putBoolean(TP_AD, o).apply();
    }


    public void setIsGuideAutoPlay(boolean isGuide) {
        mStore.edit().putBoolean(AUTO_PLAY_GUIDE, isGuide).apply();
    }

    public boolean isShowGuideAutoPlay() {
        return mStore.getBoolean(AUTO_PLAY_GUIDE, true);
    }

    private Store() {
        mStore = ShuaApplication.getContext().getSharedPreferences(SP_RX, Context.MODE_PRIVATE);
    }

    public static Store getInstance() {
        if (null == instance) {
            synchronized (Store.class) {
                if (null == instance) {
                    instance = new Store();
                }
            }
        }
        return instance;
    }

    public boolean isLogin() {
        String token = ShuaApplication.token;
        if (!TextUtils.isEmpty(token)) {
            return true;
        }
        return false;
    }

    public void saveConfigInfo(ConfigInfo configInfo) {
        if (configInfo == null) {
            return;
        }
        int rate = configInfo.getHome_ad_refresh_rate();
        if (rate <= 0) {
            rate = 4;
        }
        setAdvertRate(rate);
        int horizontalRate = configInfo.getAdvert_video_ad_num();
        if (horizontalRate <= 0) {
            horizontalRate = 1;
        }
        setHorizontalRate(horizontalRate);
    }

    public void saveHorizontalConfig(List<AdvertConfigBean> drawing) {
        if (drawing == null || drawing.size() < 1) {
            return;
        }
        try {
            Gson gson = new Gson();
            String jsonStr = gson.toJson(drawing);
            mStore.edit().putString(ADVERT_HORIZONTAL, jsonStr).apply();
        } catch (Exception ignored) {

        }
    }

    public List<AdvertConfigBean> getHorizontalConfig() {
        try {
            String drawJson = mStore.getString(ADVERT_HORIZONTAL, "");
            if (TextUtils.isEmpty(drawJson)) {
                return null;
            }
            Gson gson = new Gson();
            return gson.fromJson(drawJson, new TypeToken<List<AdvertConfigBean>>() {
            }.getType());
        } catch (Exception e) {
            return null;
        }
    }

    public void saveDrawConfig(List<AdvertConfigBean> drawing) {
        if (drawing == null || drawing.size() < 1) {
            return;
        }
        try {
            Gson gson = new Gson();
            String jsonStr = gson.toJson(drawing);
            mStore.edit().putString(ADVERT_DRAW, jsonStr).apply();
        } catch (Exception ignored) {

        }
    }

    public List<AdvertConfigBean> getDrawConfig() {
        try {
            String drawJson = mStore.getString(ADVERT_DRAW, "");
            if (TextUtils.isEmpty(drawJson)) {
                return null;
            }
            Gson gson = new Gson();
            return gson.fromJson(drawJson, new TypeToken<List<AdvertConfigBean>>() {
            }.getType());
        } catch (Exception e) {
            return null;
        }
    }


    public void saveOpenConfig(List<AdvertConfigBean> open) {
        if (open == null || open.size() < 1) {
            return;
        }
        try {
            Gson gson = new Gson();
            String jsonStr = gson.toJson(open);
            mStore.edit().putString(ADVERT_OPEN, jsonStr).apply();
        } catch (Exception ignored) {

        }
    }

    public List<AdvertConfigBean> getOpenConfig() {
        try {
            String openJson = mStore.getString(ADVERT_OPEN, "");
            if (TextUtils.isEmpty(openJson)) {
                return null;
            }
            Gson gson = new Gson();
            return gson.fromJson(openJson, new TypeToken<List<AdvertConfigBean>>() {
            }.getType());
        } catch (Exception e) {
            return null;
        }
    }

    public void setOpenIndex(int index) {
        mStore.edit().putInt(INDEX_OPEN, index).apply();
    }

    public int getOpenIndex() {
        return mStore.getInt(INDEX_OPEN, -1);
    }

    public void setDrawIndex(int index) {
        mStore.edit().putInt(INDEX_DRAW, index).apply();
    }

    public int getDrawIndex() {
        return mStore.getInt(INDEX_DRAW, -1);
    }

    public void setNativeCashIndex(int index) {
        mStore.edit().putInt(INDEX_NATIVE_CASH, index).apply();
    }

    public int getNativeCashIndex() {
        return mStore.getInt(INDEX_NATIVE_CASH, -1);
    }

    public void setNativeCommonIndex(int index) {
        mStore.edit().putInt(INDEX_NATIVE_COMMON, index).apply();
    }

    public int getNativeCommonIndex() {
        return mStore.getInt(INDEX_NATIVE_COMMON, -1);
    }

    public void setNativeRewardIndex(int index) {
        mStore.edit().putInt(INDEX_NATIVE_REWARD, index).apply();
    }

    public int getNativeRewardIndex() {
        return mStore.getInt(INDEX_NATIVE_REWARD, -1);
    }

    public void setButtleIndex(int index) {
        mStore.edit().putInt(INDEX_BUTTLE, index).apply();
    }

    public int getButtleIndex() {
        return mStore.getInt(INDEX_BUTTLE, -1);
    }

    public void setButtleFirstGuide(Boolean guide) {
        mStore.edit().putBoolean(BUTTLE_FIRST_GUIDE, guide).apply();
    }

    public boolean getButtleFirstGuide() {
        return mStore.getBoolean(BUTTLE_FIRST_GUIDE, false);
    }

    public void setButtleLastGuide(Boolean guide) {
        mStore.edit().putBoolean(BUTTLE_LAST_GUIDE, guide).apply();
    }

    public boolean getButtleLastGuide() {
        return mStore.getBoolean(BUTTLE_LAST_GUIDE, false);
    }


    public void setGoldGuideEnable(boolean isGuide) {
        mStore.edit().putBoolean(IS_GOLD_GUIDE + getuserId(), isGuide).apply();
    }

    public boolean isGoldGuide() {
        return mStore.getBoolean(IS_GOLD_GUIDE + getuserId(), true);
    }

    public void setProxy(boolean isProxy) {
        mStore.edit().putBoolean(IS_PROXY, isProxy).apply();
    }

    public boolean isProxy() {
        return mStore.getBoolean(IS_PROXY, false);
    }

    public void setAdvertRate(int rate) {
        mStore.edit().putInt(ADVERT_RATE, rate).apply();
    }

    public int getAdvertRate() {
        return mStore.getInt(ADVERT_RATE, 4);
    }

    public void setHorizontalRate(int rate) {
        mStore.edit().putInt(HORIZONTAL_RATE, rate).apply();
    }

    public int getHorizontalRate() {
        return mStore.getInt(HORIZONTAL_RATE, 4);
    }

    public void setIsNewUser(Boolean privacy) {
        mStore.edit().putBoolean(IS_NEW_USER, privacy).apply();
    }

    public Boolean getIsNewUser() {
        return mStore.getBoolean(IS_NEW_USER, false);
    }

    public void setFirstAd(Boolean isFirst) {
        mStore.edit().putBoolean(FIRST_AD, isFirst).apply();
    }

    public Boolean getFirstAd() {
        return mStore.getBoolean(FIRST_AD, false);
    }

    public void setVivoOpen(Boolean isOpen) {
        mStore.edit().putBoolean(IS_VIVO_OPEN, isOpen).apply();
    }

    public Boolean getVivoOpen() {
        return mStore.getBoolean(IS_VIVO_OPEN, false);
    }

    public void setHuaweiOpen(Boolean isOpen) {
        mStore.edit().putBoolean(IS_HUAWEI_OPEN, isOpen).apply();
    }

    public Boolean getHuaweiOpen() {
        return mStore.getBoolean(IS_HUAWEI_OPEN, false);
    }

    public void setXiaomiOpen(Boolean isOpen) {
        mStore.edit().putBoolean(IS_XIAOMI_OPEN, isOpen).apply();
    }

    public Boolean getXiaomiOpen() {
        return mStore.getBoolean(IS_XIAOMI_OPEN, false);
    }

    public void setAdmobileOpen(Boolean isOpen) {
        mStore.edit().putBoolean(IS_ADMOBILE_OPEN, isOpen).apply();
    }

    public Boolean isAdmobileOpen() {
        return mStore.getBoolean(IS_ADMOBILE_OPEN, false);
    }

    public void setTuiaHomeOpen(Boolean isOpen) {
        mStore.edit().putBoolean(IS_TUIA_HOME_OPEN, isOpen).apply();
    }

    public Boolean isTuiaHomeOpen() {
        return mStore.getBoolean(IS_TUIA_HOME_OPEN, false);
    }

    public void setTuiaTaskOpen(Boolean isOpen) {
        mStore.edit().putBoolean(IS_TUIA_TASK_OPEN, isOpen).apply();
    }

    public Boolean isTuiaTaskOpen() {
        return mStore.getBoolean(IS_TUIA_TASK_OPEN, false);
    }

    public void setBxmOpen(Boolean isOpen) {
        mStore.edit().putBoolean(IS_BXM_OPEN, isOpen).apply();
    }

    public Boolean isBxmOpen() {
        return mStore.getBoolean(IS_BXM_OPEN, false);
    }

    public void setHwAdOpen(Boolean isOpen) {
        mStore.edit().putBoolean(IS_HW_AD_OPEN, isOpen).apply();
    }

    public Boolean isHwAdOpen() {
        return mStore.getBoolean(IS_HW_AD_OPEN, false);
    }

    public void setIsAdOpen(Boolean isAdOpen) {
        mStore.edit().putBoolean(IS_AD_OPEN, isAdOpen).apply();
    }

    public Boolean isFirstStart() {
        return mStore.getBoolean(IS_FIRST_START, false);
    }

    public void setFirstStart(Boolean isAdOpen) {
        mStore.edit().putBoolean(IS_FIRST_START, isAdOpen).apply();
    }

    public Boolean isRemindLocation() {
        return mStore.getBoolean(IS_REMIND_LOCATION, false);
    }

    public void setRemindLocation(Boolean isRemind) {
        mStore.edit().putBoolean(IS_REMIND_LOCATION, isRemind).apply();
    }

    public Boolean getNewUserPopup() {
        return mStore.getBoolean(IS_NEWUSER_POPUOP, false);
    }

    public void setNewUserPopup(Boolean isAdOpen) {
        mStore.edit().putBoolean(IS_NEWUSER_POPUOP, isAdOpen).apply();
    }

    public Boolean getIsAdOpen() {
        return mStore.getBoolean(IS_AD_OPEN, false);
    }

    public void setIsAdNewOpen(Boolean isAdNewOpen) {
        mStore.edit().putBoolean(IS_AD_NEW_OPEN, isAdNewOpen).apply();
    }

    public Boolean getIsAdNewOpen() {
        return mStore.getBoolean(IS_AD_NEW_OPEN, false);
    }

    public void setIsAdOldOpen(Boolean isAdOldOpen) {
        mStore.edit().putBoolean(IS_AD_OLD_OPEN, isAdOldOpen).apply();
    }

    public Boolean getIsAdOldOpen() {
        return mStore.getBoolean(IS_AD_OLD_OPEN, false);
    }

    public void setAdSkipTime(int time) {
        mStore.edit().putInt(AD_SKIP_TIME, time).apply();
    }

    public int getAdSkipTime() {
        return mStore.getInt(AD_SKIP_TIME, 2);
    }

    public void setLastLocation(String city) {
        mStore.edit().putString(LAST_LOCATION, city).apply();
    }

    public String getLastLocation() {
        return mStore.getString(LAST_LOCATION, "");
    }

    public void setMistakeConfig(String config) {
        mStore.edit().putString(MISTAKE_CONFIG, config).apply();
    }

    public String getMistakeConfig() {
        return mStore.getString(MISTAKE_CONFIG, "");
    }

    public void setuserId(String userId) {
        mStore.edit().putString(USER_ID, userId).apply();
    }

    public String getuserId() {
        return mStore.getString(USER_ID, "");
    }

    public void setUserPhone(String userId) {
        mStore.edit().putString(USER_PHONE, userId).apply();
    }

    public String getUserPhone() {
        return mStore.getString(USER_PHONE, "");
    }


    public void setToken(String token) {
        mStore.edit().putString(TOKEN, token).apply();
    }

    public String getToken() {
        return mStore.getString(TOKEN, "");
    }

    public void setAccessToken(String token) {
        mStore.edit().putString(ACCESS_TOKEN, token).apply();
    }

    public String getAccessToken() {
        return mStore.getString(ACCESS_TOKEN, "");
    }

    public void setOpenId(String openId) {
        mStore.edit().putString(OPEN_ID, openId).apply();
    }

    public String getOpenId() {
        return mStore.getString(OPEN_ID, "");
    }

    public void setType(String type) {
        mStore.edit().putString(WECHAT, type).apply();
    }

    public String getType() {
        return mStore.getString(WECHAT, "");
    }

    public void setVideoId(String videoId) {
        mStore.edit().putString(VIDEO_ID, videoId).apply();
    }

    public String getVideoId() {
        return mStore.getString(VIDEO_ID, "");
    }

    public void setPrivacy(Boolean privacy) {
        mStore.edit().putBoolean(isPRIVACY, privacy).apply();
    }

    public Boolean getPrivacy() {
        return mStore.getBoolean(isPRIVACY, false);
    }

    public void setBackTasksTime(String userId) {
        mStore.edit().putString(BACK_TASKS_TIME, userId).apply();
    }

    public String getBackTasksTime() {
        return mStore.getString(BACK_TASKS_TIME, "");
    }

    public void setAgent_code(String type) {
        mStore.edit().putString(agent_code, type).apply();
    }

    public String getAgent_code() {
        return mStore.getString(agent_code, "");
    }

    public void setUserName(String type) {
        mStore.edit().putString(USER_NAME, type).apply();
    }

    public String getUserName() {
        return mStore.getString(USER_NAME, "");
    }

    public boolean isCalendarReminded() {
        return mStore.getBoolean(CALENDAR_IS_REMIND, false);
    }

    public void setCalendarReminded(boolean isRemind) {
        mStore.edit().putBoolean(CALENDAR_IS_REMIND, isRemind).apply();
    }

    public void loginSuccess(Context context, String token_type, String access_token, String logType) {
        loginSuccess(context, token_type, access_token, null, logType);
    }

    public void loginSuccess(Context context, String token_type, String access_token, LoginBean.DataBean loginDataBean, String logType) {
        String token = token_type + " " + access_token;
        ShuaApplication.token = token;
        setToken(token);
        ShuaApplication.accessToken = access_token;
        setAccessToken(access_token);
        ToastUtil.showToast(context, "登录成功");
        HttpData.getInstance().getMe(new ACallback<Me>() {
            @Override
            public void onSuccess(Me data) {
                if (data.isStatus()) {
                    //别名增加，将某一类型的别名ID绑定至某设备，老的绑定设备信息还在，别名ID和device_token是一对多的映射关系
                    PushAgent.getInstance(context).setAlias(data.getData().getLogin_user_id() + "", "ALIAS_TYPE_LOGIN", (isSuccess, message) -> {
                    });
                    ShuaApplication.game_status = data.getData().isGame_status();
                    Store.getInstance().setNEW_OR_OLD(data.getData().isNew_or_old());//新老用户
                    //友盟绑定账号
                    MobclickAgent.onProfileSignIn(logType, data.getData().getLogin_user_id() + "");
                    setuserId(data.getData().getLogin_user_id() + "");
                    setUserPhone(data.getData().getLogin_user_mobile() + "");
                    ShuaApplication.is_bind_wechat = data.getData().isIs_bind_wechat();
                }
            }

            @Override
            public void onFail(int errCode, String errMsg) {
                LogUtil.d(errMsg);
            }
        });
        //上报渠道的注册数
        ReportChannelManager.getInstance().reportChannelData(3);
        Intent intent = new Intent(context, MainActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        if (loginDataBean != null) {
            intent.putExtra("loginDataBean", loginDataBean);
        }
        context.startActivity(intent);
    }

    private void clearData() {
        ShuaApplication.token = "";
        setToken("");
        ShuaApplication.accessToken = "";
        setAccessToken("");
        setType("");
        setOpenId("");
        setButtleFirstGuide(false);
        setButtleLastGuide(false);
    }

    public void logout(Context context) {
        MobclickAgent.onProfileSignOff();//友盟退出登入
        clearData();
        Intent intent = new Intent(context, LoginActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        intent.putExtra("action", "logout");
        context.startActivity(intent);
    }

    public void logoutFromH5Page(Activity context) {
        MobclickAgent.onProfileSignOff();//友盟退出登入
        clearData();
        Intent intent = new Intent(context, LoginActivity.class);
        context.startActivity(intent);
    }

    public void logoutSiglent(Context context) {
        MobclickAgent.onProfileSignOff();//友盟退出登入
        clearData();
    }

    //判断广告是不是第一次启动app
    public boolean isADNewUser() {
        return getNewUserTpAd() <= 1;
//        return false;
    }

}
